package com.moju.serviceImpl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.moju.mapper.ProductMapper;
import com.moju.pojo.Product;
import com.moju.service.ProductService;
import com.moju.util.Constant;
import com.moju.util.SqlSessionUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class ProductServiceImpl implements ProductService {


    @Override
    public PageInfo<Product> getProductByLikeWithLimit(String like,Integer pageNo) throws Exception {
        //设置页码， 页大小
        PageHelper.startPage(pageNo , Constant.PAGE_SIZE);

        SqlSession sqlSession = SqlSessionUtil.getSqlSession();

        ProductMapper mapper = sqlSession.getMapper(ProductMapper.class);

        List<Product> list = mapper.getProductsByLike(like);
        //返回分页对象
        PageInfo<Product> pager = new PageInfo<>(list);

        return pager;
    }
}
